{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_start": false } }, "source": [ "# Interactive monitoring of a parallel MPI simulation from a notebook\n", "\n", "first, start a cluster with mpi.\n", "\n", "Or load an existing cluster with e.g.\n", "\n", "```python\n", "cluster = Cluster.from_file(profile=\"mpi\")\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_start": false } }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from IPython.display import display\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using existing profile dir: '/Users/minrk/.ipython/profile_default'\n", "Starting 4 engines with \n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8b14b3b6f0cb4a67be4645c8274c4074", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/4 [00:00" ] }, "metadata": { "image/png": { "height": 365, "width": 572 } }, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Monitoring interrupted, simulation is ongoing!\n", "Monitored for: 0:00:19.277042.\n" ] } ], "source": [ "monitor_simulation(refresh=1);" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_start": false } }, "source": [ "If you execute the following cell before the MPI code is finished running, it will stop the simulation at that point, which you can verify by calling the monitoring again:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "slideshow": { "slide_start": false } }, "outputs": [], "source": [ "view['stop'] = True" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[stdout:0] \n", "{\n", " \"shell_port\": 57579,\n", " \"iopub_port\": 57580,\n", " \"stdin_port\": 57581,\n", " \"control_port\": 57583,\n", " \"hb_port\": 57582,\n", " \"ip\": \"127.0.0.1\",\n", " \"key\": \"944dac79-816e4a12e48b45baf11ab5e8\",\n", " \"transport\": \"tcp\",\n", " \"signature_scheme\": \"hmac-sha256\",\n", " \"kernel_name\": \"\"\n", "}\n", "\n", "Paste the above JSON into a file, and connect with:\n", " $> jupyter --existing \n", "or, if you are local, you can connect with just:\n", " $> jupyter --existing /Users/minrk/.ipython/profile_default/security/kernel-46128.json\n", "or even just:\n", " $> jupyter --existing\n", "if this is the most recent Jupyter kernel you have started.\n" ] } ], "source": [ "%%px --target 0 --block\n", "from ipyparallel import bind_kernel; bind_kernel()\n", "%connect_info" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "%%px --target 0 --block\n", "%qtconsole" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "02f2d94254d542bdbd3cff7f9bc035e7": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "bar_style": "success", "layout": "IPY_MODEL_4cdefd8ae5764be8a8bf1f3c374492f0", "max": 4, "style": "IPY_MODEL_d101b978f358462fbcc0ad51c4be1ee1", "value": 4 } }, "0ab41c84c30445dfa2c77e0e2014dd46": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "11097de7cc114cc88d99cd17a693d510": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "20d1375897eb4fdcb87fda73573ad678": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HBoxModel", "state": { "children": [ "IPY_MODEL_7a50e71a222340a4ba51e70ef3abce47", "IPY_MODEL_02f2d94254d542bdbd3cff7f9bc035e7", "IPY_MODEL_876517d46fa6488f8fb61db3ed689b96" ], "layout": "IPY_MODEL_0ab41c84c30445dfa2c77e0e2014dd46" } }, "212854fc12af402eb3a57438a851dfac": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "2231573544774560984193c60e6370cb": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "4205fec62aea485c8ffaf31ca98859aa": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "4cdefd8ae5764be8a8bf1f3c374492f0": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "5143e78c3dcc439a95b7ec24ea37c2be": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "6817e30d6c824bd194e102e20a9e7cda": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "6be3837161754e08a715ac0c78fa1080": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "7a50e71a222340a4ba51e70ef3abce47": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "layout": "IPY_MODEL_2231573544774560984193c60e6370cb", "style": "IPY_MODEL_6817e30d6c824bd194e102e20a9e7cda", "value": "100%" } }, "7afda4d37ef841c684bb624ff6b19267": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "811e5930f3bc42899a5e700d9b275bdb": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "876517d46fa6488f8fb61db3ed689b96": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "layout": "IPY_MODEL_11097de7cc114cc88d99cd17a693d510", "style": "IPY_MODEL_7afda4d37ef841c684bb624ff6b19267", "value": " 4/4 [00:05<00:00, 5.54s/engine]" } }, "88e7ff230d284b368ace25166967a93d": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "layout": "IPY_MODEL_6be3837161754e08a715ac0c78fa1080", "style": "IPY_MODEL_5143e78c3dcc439a95b7ec24ea37c2be", "value": "100%" } }, "8b14b3b6f0cb4a67be4645c8274c4074": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HBoxModel", "state": { "children": [ "IPY_MODEL_88e7ff230d284b368ace25166967a93d", "IPY_MODEL_eee11ad7360e4cc2b6b2f196ff4a1d45", "IPY_MODEL_9d0e878210c24c93bc764ec9ec53b84e" ], "layout": "IPY_MODEL_a15b2b7fec55486689859c321b2ca7e3" } }, "9d0e878210c24c93bc764ec9ec53b84e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "layout": "IPY_MODEL_811e5930f3bc42899a5e700d9b275bdb", "style": "IPY_MODEL_212854fc12af402eb3a57438a851dfac", "value": " 4/4 [00:06<00:00, 6.12s/engine]" } }, "a15b2b7fec55486689859c321b2ca7e3": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "afa1055878c444c49c4db6767994e04b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "description_width": "" } }, "d101b978f358462fbcc0ad51c4be1ee1": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "description_width": "" } }, "eee11ad7360e4cc2b6b2f196ff4a1d45": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "bar_style": "success", "layout": "IPY_MODEL_4205fec62aea485c8ffaf31ca98859aa", "max": 4, "style": "IPY_MODEL_afa1055878c444c49c4db6767994e04b", "value": 4 } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }